//项目-红外遥控数码管_1 
#include<IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
int currentNumber = 0;
long codes[12] = {
  0xE916FF00 , 0xF30CFF00 , 0xE718FF00 , 
  0xA15EFF00 , 0xF708FF00 , 0xE31CFF00 , 
  0xA55AFF00 , 0xBD42FF00 , 0xAD52FF00 , 
  0xB54AFF00 , 0xBB44FF00 , 0xBF40FF00 ,
};
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  irrecv.enableIRIn();

for(int pin = 2;pin<=9;pin++){
  pinMode(pin,OUTPUT);
  digitalWrite(pin,HIGH);
  }
}

void loop() {
  // put your main code here, to run repeatedly.
  if(irrecv.decode()){
    long RawData = irrecv.decodedIRData.decodedRawData;
    for(int i=0;i<=11;i++){
      if(RawData == codes[i]&&i<=9){
        numberShow(i);
        currentNumber = i;
        Serial.println(i);
        break;
      }else if(RawData == codes[10]&&currentNumber != 0){
        currentNumber--;
        numberShow(currentNumber);
        Serial.println(currentNumber);
        break;
      }else if(RawData == codes[11]&&currentNumber != 9){
        currentNumber++;
        numberShow(currentNumber);
        Serial.println(currentNumber);
        break;
      }
    }
    Serial.println(RawData,HEX);
    irrecv.resume();
  }
}
void numberShow(int i){
 int number[10][8] = {
  {0,0,0,1,0,0,0,1},//0
  {0,1,1,1,1,1,0,1},//1
  {0,0,1,0,0,0,1,1},//2
  {0,0,1,0,1,0,0,1},//3
  {0,1,0,0,1,1,0,1},//4
  {1,0,0,0,1,0,0,1},//5
  {1,0,0,0,0,0,0,1},//6
  {0,0,1,1,1,1,0,1},//7
  {0,0,0,0,0,0,0,1},//8
  {0,0,0,0,1,0,0,1},//9
  };

  for(int pin = 2;pin<=9;pin++){
    digitalWrite(pin,number[i][pin-2]);
  }
}
